import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiWeatherPage(Base):
    """
    语音训练天气技能

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.weather_home_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("ivHome"))

        # 左侧的返回键
        self.weather_back_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format('ivBack'))

        # 已选择标题
        self.weather_select_city_title_text = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("tv_choose"))

        # 选择城市
        self.weather_select_city_text = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("tv_city_none"))

        # 当前城市
        self.weather_now_city_title_text = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("tv_curr"))

        # 城市图标
        self.weather_city_icon = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("icon_location"))

        # 城市名称
        self.weather_city_name_text = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("location_tv"))

        # 字母列表
        self.weather_letter_list_icon = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("sideBar"))

        # 滑动条
        self.weather_switch_icon = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("scrollbar"))

        # 手动选择标题
        # self.weather_manual_selection_title_text = (By.XPATH, Yomi.manual_selection_title_text.format(""))
        self.weather_manual_selection_title_text = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("textView10"))

        # 城市标签
        self.weather_city_initials_text = (By.XPATH, Yomi.city_initials_text.format(""))

        # 城市名称
        self.weather_list_city_name_text = (By.XPATH, Yomi.city_name_text.format(""))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.weather_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.weather_home_btn)

    def get_select_city_title(self):
        """
        获取天气已选择标题

        :return:获取元素
        """
        return self.find_element_o(self.weather_select_city_title_text)

    def get_select_city(self):
        """
        获取天气选择城市

        :return:获取元素
        """
        return self.find_element_o(self.weather_select_city_text)

    def get_now_city_title(self):
        """
        获取当前城市

        :return:获取元素
        """
        return self.find_element_o(self.weather_now_city_title_text)

    def get_city(self):
        """
        获取城市图标

        :return:获取元素
        """
        return self.find_element_o(self.weather_city_icon)

    def get_city_name(self):
        """
        获取城市名称

        :return:获取元素
        """
        return self.find_element_o(self.weather_city_name_text)

    def get_letter_list(self):
        """
        获取字母列表

        :return:获取元素
        """
        return self.find_element_o(self.weather_letter_list_icon)

    def get_switch(self):
        """
        获取滑动条

        :return:获取元素
        """
        return self.find_element_o(self.weather_switch_icon)

    def get_manual_selection_title(self):
        """
        手动选择标题

        :return:获取元素
        """
        # self.weather_manual_selection_title_text = (By.XPATH, Yomi.manual_selection_title_text.format(index))
        return self.find_element_o(self.weather_manual_selection_title_text)

    def get_city_initials(self, index=2):
        """
        城市标签

        :return:获取元素
        """
        self.weather_city_initials_text = (By.XPATH, Yomi.city_initials_text.format(index))
        return self.find_element_o(self.weather_city_initials_text)

    def swipe_weather_list(self):
        """
        滑动城市列表

        :return:None
        """
        self.swipe_o(location=(765, 765, 470, 660), direction='up')

    def get_list_city_name(self, index=2):
        """
        城市名称

        :return:获取元素
        """
        self.weather_list_city_name_text = (By.XPATH, Yomi.city_name_text.format(index))
        return self.find_element_o(self.weather_list_city_name_text)

    def click_list_city_name(self, index=2):
        """
        点击点击城市名称

        :return:None
        """
        self.weather_list_city_name_text = (By.XPATH, Yomi.city_name_text.format(index))
        self.click_element(self.weather_list_city_name_text)

    def is_display_yomi_weather(self):
        """
        查看是否进入语音训练天气
        :return:
        """
        return self.is_display(self.weather_select_city_title_text)
